﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace lcmyjobs.DAL
{
	/// <summary>
	/// 数据访问类:enterprise_top
	/// </summary>
	public partial class enterprise_top
	{
		public enterprise_top()
		{}
        /// <summary>
        /// 固定会员
        /// </summary>
        /// <param name="enterprise_lid"></param>
        /// <param name="checktime">更改审核通过时间</param>
        /// <param name="status">更改状态为1 通过</param>
        /// <returns></returns>
        public int UpdateTop(int enterprise_top_id, DateTime topchecktime, int status)
        {
            //string sql = " update enterprise_top set topchecktime='" + topchecktime + "',status=" + status + " where enterprise_top_id= " + enterprise_top_id;
            SqlParameter[] para = 
            {
                new SqlParameter("@enterprise_top_id ",SqlDbType.Int),
            };
            para[0].Value = enterprise_top_id;
            DbHelperSQL.RunProcedure("P_update_enterprise_top", para, "ds");
            return 1;

        }
        /// <summary>
        /// 获取单位固定信息
        /// </summary>
        /// <param name="atid">网站类别</param>
        /// <param name="currentPageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public DataSet GetTopInfo(int atid, int currentPageIndex, int pageSize, out int count)
        {
            SqlParameter[] para = 
            {
                new SqlParameter("@atid",SqlDbType.Int),
                new SqlParameter("@currentPageIndex",SqlDbType.Int),
                new SqlParameter("@pageSize",SqlDbType.Int),
                new SqlParameter("@count",SqlDbType.Int)
            };

            para[0].Value = atid;
            para[1].Value = currentPageIndex;
            para[2].Value = pageSize;
            para[3].Direction = ParameterDirection.Output;

            DataSet ds = DbHelperSQL.RunProcedure("P_Get_enterprise_topInfo", para, "ds");

            count = Convert.ToInt32(para[3].Value);

            return ds;
        }
        #region  Method

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return DbHelperSQL.GetMaxID("enterprise_top_id", "enterprise_top");
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int enterprise_top_id)
        {
            int rowsAffected;
            SqlParameter[] parameters = {
					new SqlParameter("@enterprise_top_id", SqlDbType.Int,4)};
            parameters[0].Value = enterprise_top_id;

            int result = DbHelperSQL.RunProcedure("enterprise_top_Exists", parameters, out rowsAffected);
            if (result == 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        ///  增加一条数据
        /// </summary>
        public bool Add(lcmyjobs.Model.enterprise_top model)
        {
            int rowsAffected;
            SqlParameter[] parameters = {
					//new SqlParameter("@enterprise_top_id", SqlDbType.Int,4),
					new SqlParameter("@enterprise_bid", SqlDbType.Int,4),
					//new SqlParameter("@toptime", SqlDbType.DateTime),
					new SqlParameter("@topapplicationtime", SqlDbType.DateTime),
					//new SqlParameter("@topchecktime", SqlDbType.DateTime),
					new SqlParameter("@timecount", SqlDbType.SmallInt,2),
					new SqlParameter("@price", SqlDbType.Float,8),
					new SqlParameter("@status", SqlDbType.TinyInt,1)};
            //parameters[0].Value = model.enterprise_top_id;
            parameters[0].Value = model.enterprise_bid;
            //parameters[2].Value = model.toptime;
            parameters[1].Value = model.topapplicationtime;
            //parameters[4].Value = model.topchecktime;
            parameters[2].Value = model.timecount;
            parameters[3].Value = model.price;
            parameters[4].Value = model.status;

            DbHelperSQL.RunProcedure("P_Add_enterprise_top", parameters, out rowsAffected);
            if (rowsAffected >0)
            {
                return true;
            }
            else
            {
                return false;
            }
            
        }

        /// <summary>
        ///  更新一条数据
        /// </summary>
        public bool Update(lcmyjobs.Model.enterprise_top model)
        {
            int rowsAffected = 0;
            SqlParameter[] parameters = {
					new SqlParameter("@enterprise_top_id", SqlDbType.Int,4),
					new SqlParameter("@enterprise_bid", SqlDbType.Int,4),
					new SqlParameter("@toptime", SqlDbType.DateTime),
					new SqlParameter("@topapplicationtime", SqlDbType.DateTime),
					new SqlParameter("@topchecktime", SqlDbType.DateTime),
					new SqlParameter("@timecount", SqlDbType.SmallInt,2),
					new SqlParameter("@price", SqlDbType.Float,8),
					new SqlParameter("@status", SqlDbType.TinyInt,1)};
            parameters[0].Value = model.enterprise_top_id;
            parameters[1].Value = model.enterprise_bid;
            parameters[2].Value = model.toptime;
            parameters[3].Value = model.topapplicationtime;
            parameters[4].Value = model.topchecktime;
            parameters[5].Value = model.timecount;
            parameters[6].Value = model.price;
            parameters[7].Value = model.status;

            DbHelperSQL.RunProcedure("enterprise_top_Update", parameters, out rowsAffected);
            if (rowsAffected > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int enterprise_top_id)
        {
            int rowsAffected = 0;
            SqlParameter[] parameters = {
					new SqlParameter("@enterprise_top_id", SqlDbType.Int,4)};
            parameters[0].Value = enterprise_top_id;

            DbHelperSQL.RunProcedure("enterprise_top_Delete", parameters, out rowsAffected);
            if (rowsAffected > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string enterprise_top_idlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from enterprise_top ");
            strSql.Append(" where enterprise_top_id in (" + enterprise_top_idlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public lcmyjobs.Model.enterprise_top GetModel(int enterprise_top_id)
        {
            SqlParameter[] parameters = {
					new SqlParameter("@enterprise_top_id", SqlDbType.Int,4)};
            parameters[0].Value = enterprise_top_id;

            lcmyjobs.Model.enterprise_top model = new lcmyjobs.Model.enterprise_top();
            DataSet ds = DbHelperSQL.RunProcedure("enterprise_top_GetModel", parameters, "ds");
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["enterprise_top_id"] != null && ds.Tables[0].Rows[0]["enterprise_top_id"].ToString() != "")
                {
                    model.enterprise_top_id = int.Parse(ds.Tables[0].Rows[0]["enterprise_top_id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["enterprise_bid"] != null && ds.Tables[0].Rows[0]["enterprise_bid"].ToString() != "")
                {
                    model.enterprise_bid = int.Parse(ds.Tables[0].Rows[0]["enterprise_bid"].ToString());
                }
                if (ds.Tables[0].Rows[0]["toptime"] != null && ds.Tables[0].Rows[0]["toptime"].ToString() != "")
                {
                    model.toptime = DateTime.Parse(ds.Tables[0].Rows[0]["toptime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["topapplicationtime"] != null && ds.Tables[0].Rows[0]["topapplicationtime"].ToString() != "")
                {
                    model.topapplicationtime = DateTime.Parse(ds.Tables[0].Rows[0]["topapplicationtime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["topchecktime"] != null && ds.Tables[0].Rows[0]["topchecktime"].ToString() != "")
                {
                    model.topchecktime = DateTime.Parse(ds.Tables[0].Rows[0]["topchecktime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["timecount"] != null && ds.Tables[0].Rows[0]["timecount"].ToString() != "")
                {
                    model.timecount = int.Parse(ds.Tables[0].Rows[0]["timecount"].ToString());
                }
                if (ds.Tables[0].Rows[0]["price"] != null && ds.Tables[0].Rows[0]["price"].ToString() != "")
                {
                    model.price = decimal.Parse(ds.Tables[0].Rows[0]["price"].ToString());
                }
                if (ds.Tables[0].Rows[0]["status"] != null && ds.Tables[0].Rows[0]["status"].ToString() != "")
                {
                    model.status = int.Parse(ds.Tables[0].Rows[0]["status"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select enterprise_top_id,enterprise_bid,toptime,topapplicationtime,topchecktime,timecount,price,status ");
            strSql.Append(" FROM enterprise_top ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

          /// <summary>
        /// 获得数据列表,表2是企业名字
        /// </summary>
        public DataSet GetList(int enterprise_bid)
        {
            SqlParameter[] para = { new SqlParameter("@enterprise_bid", SqlDbType.Int) };

            para[0].Value = enterprise_bid;

            return DbHelperSQL.RunProcedure("P_Get_enterprise_top", para, "ds");
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" enterprise_top_id,enterprise_bid,toptime,topapplicationtime,topchecktime,timecount,price,status ");
            strSql.Append(" FROM enterprise_top ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "enterprise_top";
            parameters[1].Value = "enterprise_top_id";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  Method
	}
}

